package com.library.controller.user;

import com.library.dto.PageQueryDTO;
import com.library.result.PageResult;
import com.library.result.Result;
import com.library.service.StatisticsService;
import com.library.vo.BookCountByBorrowedVO;
import com.library.vo.BookCountByCategoryVO;
import com.library.vo.BookCountByPriceVO;
import com.library.vo.BookCountByYearVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.implementation.bytecode.constant.DefaultValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/user/statistics")
@Slf4j
@Api(tags = "图书统计相关接口")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @GetMapping("/category")
    @ApiOperation("根据分类获取图书统计")
    public Result<List<BookCountByCategoryVO>> getBookCountByCategory() {
        List<BookCountByCategoryVO> bookCountByCategoryVOList = statisticsService.getBookCountByCategory();
        return Result.success(bookCountByCategoryVOList);
    }

    @GetMapping("/publishedyear")
    @ApiOperation("根据年份获取图书统计")
    public Result<List<BookCountByYearVO>>  getBookCountByPublishedYear() {
        List<BookCountByYearVO> bookCountByYearVOList = statisticsService.getBookCountByPublishedYear();
        return Result.success(bookCountByYearVOList);
    }

    @GetMapping("/price")
    @ApiOperation("根据价格获取图书统计")
    public Result<List<BookCountByPriceVO>> getBookCountByPrice() {
        List<BookCountByPriceVO> bookCountByPriceVOList = statisticsService.getBookCountByPrice();
        return Result.success(bookCountByPriceVOList);
    }

    @GetMapping("/borrowed")
    @ApiOperation("获取借阅次数图书排名")
    public Result<PageResult> getBookCountByBorrowed(PageQueryDTO pageQueryDTO) {
        PageResult pageResult = statisticsService.getBookCountByBorrowed(pageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/browse")
    @ApiOperation("获取浏览次数图书排名")
    public Result<PageResult> getBookCountByBrowse(PageQueryDTO pageQueryDTO) {
        PageResult pageResult = statisticsService.getBookCountByBrowse(pageQueryDTO);
        return Result.success(pageResult);
    }

}
